<template>
  <!--  分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="t in roleList" :key="t.id" :label="t.id">
        {{ t.name }}
      </el-checkbox>

    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="handleSubmit">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRoles } from '@/api/settings'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    show: {
      type: Boolean
    },
    id: {
      type: String,
      default: ''
    },
    assignRole: Array
  },
  data() {
    return {
      roleIds: [],
      checkList: [],
      roleList: []
    }
  },
  created() {
    this.getRoleList()
    this.roleIds = this.assignRole
  },
  methods: {
    async handleSubmit() {
      console.log(this.roleIds)
      await assignRoles({ id: this.id, roleIds: this.roleIds })

      this.$emit('update:show', false)
    },
    async getRoleList() {
      const { data: { rows }} = await getRoles(1, 10)
      this.roleList = rows
    },
    closeDialog() {
      this.$emit('update:show', false)
    }
  }
}
</script>
<style lang="">

</style>
